package com.hxc.service.impl;

import com.hxc.entity.JobOption;
import com.hxc.mapper.ReportMapper;
import com.hxc.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportMapper reportMapper;
    /**
     * 统计各各职位员工数量
     * */
    @Override
    public JobOption getEmpCountByJob() {
        List<Map<String, Object>> maps = reportMapper.getRmpCountByJob();
        List<String> jobs = maps.stream().map(map -> (String)map.get("jobs")).toList();
        List<Long> nums = maps.stream().map(map->(Long)map.get("num")).toList();
        log.info("数量统计：{}",nums);
        return new JobOption(jobs, nums);
    }
    /**
     * 统计各性别员工数量
     * */
    @Override
    public List<Map> getEmpCountByGender() {
        List<Map> maps = reportMapper.getRmpCountByGender();
        log.info("查询到{}",maps);
        return maps;
    }
    /**
     * 统计各学历学员人数
     * */
    @Override
    public List<Map> getStudentCountByDegree() {
        List<Map> maps = reportMapper.getStudentCountByDegree();
        return maps;
    }
    /**
     * 统计各班级人数
     * */
    @Override
    public Map<String, List> getStudentCountByClazz() {
        List<Map<String,Object>> maps = reportMapper.getStudentCountByClazz();
        log.info("分组查询完成：{}",maps);
        List<String> clazzList = maps.stream().map(map -> (String) map.get("name")).toList();
        List<Long> dataList = maps.stream().map(map -> (Long)map.get("num")).toList();

        return Map.of("clazzList", clazzList, "dataList", dataList);
    }
}
